package thinkinjava4.ch20_annotations;

import thinkinjava4.atunit.Test;
import thinkinjava4.util.OSExecute;

import java.io.FileInputStream;
import java.io.IOException;

public class AtUnitExample2 {
    public String methodOne() {
        return "This is methodOne";
    }

    public int methodTwo() {
        System.out.println("This is methodTwo");
        return 2;
    }

    @Test
    void assertExample() {
        assert methodOne().equals("This is methodOne");
    }

    @Test
    void assertFailureExample() {
        assert 1 == 2 : "What a surprise!";
    }

    @Test
    void exceptionExample() throws IOException {
        new FileInputStream("noFile.txt");
    }

    @Test
    boolean assertAndReturn() {
        assert methodTwo() == 2;
        return methodOne().equals("This is methodOne");
    }

    /**
     * 使用assert断言
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        OSExecute.command(OSExecute.DEFAULT_DIR, OSExecute.ATUNIT_ANN + "AtUnitExample2");
    }
}
